\documentclass[dvipsnames]{beamer}
\usepackage{graphicx}
\usepackage[utf8]{inputenc} % Kodierung
\usepackage[ngerman]{babel} % Sprache
\usepackage{listings}
\usetheme{Warsaw}
\setbeamertemplate{blocks}[rounded][shadow=true]
%\usepackage[usenames,dvipsnames]{color}
\definecolor{darkblue}{RGB}{0,32,97}
\lstset{ %set parameters for code 
  language=C,                % the language of the code
  basicstyle=\tiny,           % the size of the fonts that are used for the code
  %numbers=left,                   % where to put the line-numbers
  %numberstyle=\tiny\color{gray},  % the style that is used for the line-numbers
  %stepnumber=,
  %identifierstyle=,                   % the step between two line-numbers. If it's 1, each line 
  keywordstyle=\color{darkblue}\bfseries,          % keyword style
  commentstyle=\color{green},       % comment style
  stringstyle=\color{blue},         % string literal style
  showstringspaces=false,
  showtabs=true
}

\title{Primeval}
\author{Johannes Mory\and Christoph Linecker \and Sebastian Zanner}
\date{26.06.2012}

\begin{document}

\begin{frame}
	\titlepage
\end{frame}

\section{Primeval}

\subsection{Primeval}

\begin{frame}{Primeval}
	\begin{columns}
		\begin{column}{6cm}
			\begin{block}{Overview}
				\begin{itemize}
					\item Written in C
					\item Input: Source code written in a modified subset of C
					\item Output: Sequence of binary encoded RISC instructions (DLX-based Set)
				\end{itemize}
			\end{block}
		\end{column}
		\begin{column}{5cm}			
			\begin{block}{Structure}
				\begin{itemize}
					\item Scanner.c
					\item Parser.c
					\item SymbolTable.c
					\item CodeGenerator.c
					\item VirtualMachine.c		
				\end{itemize}
			\end{block}
		\end{column}
	\end{columns}
\end{frame}

\begin{frame}{Primeval}
	\begin{columns}
		\begin{column}{6cm}
			\begin{block}{Features}
				\begin{itemize}
					\item 1D-Arrays \& Records
					\item Memory Allocation
					\item Arithmetic Expressions
					\item If-Then-Else
					\item While-Loops
					\item Boolean Expressions \& Lazy Evaluation
					\item Procedures	
					\item Simple Integer I/O	
				\end{itemize}
			\end{block}
		\end{column}
		\begin{column}{5cm}			
			\begin{block}{To Do}
				\begin{itemize}
					\item Multidimensional Arrays
					\item Separate Compilation
					\item Self Compilation
					\item I/O Instructions
				\end{itemize}
			\end{block}
		\end{column}
	\end{columns}
\end{frame}


% code sample
\defverbatim[colored]\ScannerToken{%
\begin{lstlisting}[tabsize=2,showtabs=false]
struct key{
	int sym;
	int length;
	string_t value;
	int line;
	int column;
}
\end{lstlisting}}

\subsection{Scanner}

\begin{frame}{Scanner}
	\begin{columns}
		\begin{column}{3cm}
			\begin{block}{Scanner Token}
			\ScannerToken
			\end{block}
		\end{column}
		\begin{column}{5cm}			
			\begin{block}{Info}
				\begin{itemize}
					\item Lookup-Table for keywords $>$ 2
					\item EOF \& UNKN Symbols 
					\item Always Terminates	
				\end{itemize}
			\end{block}
		\end{column}
	\end{columns}
\end{frame}

\subsection{Parser}

\begin{frame}{Parser}
	\begin{block}{Parser}
		\begin{itemize}
			\item recursive-descent parser
			\item outputs error-messages but keeps parsing
			\item initializes scanner \& code generator
			\item calls scanner for symbols
			\item calls code generator for code specific stuff
			\item entrypoint: primeval() -$>$ includes, sequences, statements(=declarations, proceduredeclarations) ...
		\end{itemize}	
	\end{block}
\end{frame}

\subsection{Code Generator}

\begin{frame}{Code Generator}
	\begin{block}{Code Generator}
		\begin{itemize}
			\item initializes Symbol Table
			\item generates dlx-code via interfaces put(), constToReg(), prologue() ...
			\item fixes branch-addresses
			\item is aware of the target machines configuration (number \textbackslash size of registers) and state (registers in use, program counter)
			\item holds dlx code in an array of records (op, a, b, c)
			\item encodes the code to a binary file
		\end{itemize}	
	\end{block}
\end{frame}

% code sample
\defverbatim[colored]\Object{%
\begin{lstlisting}[tabsize=2,showtabs=false]
struct object
{
	string_t	name;
	int				oClass;
	type_t		tpye;
	object_t	next;
	symTab_t	params;
	int				val;
	int				scope;
	int				offset;	
}
\end{lstlisting}}

\defverbatim[colored]\Type{%
\begin{lstlisting}[tabsize=2,showtabs=false]
struct type
{
	int 	form;
	int 	len;
	int 	size;
	symTab_t	fields;
}
\end{lstlisting}}

\defverbatim[colored]\SymTab{%
\begin{lstlisting}[tabsize=2,showtabs=false]
symTab_t bottom;
symTab_t top;
int height;

struct Symtab
{
	object_t	head;
	object_t	tail;
	symTab_t lower;
	int	length;
}
\end{lstlisting}}

\defverbatim[colored]\SymTabProcedure{%
\begin{lstlisting}[tabsize=2,showtabs=false]
void push(symTab_t symTab);
void pop();
void newStage();
void addObj(symTab_t symTab,
		 object_t node);
\end{lstlisting}}

\subsection{Symbol Table}

\begin{frame}{Symbol Table}
	\begin{columns}

		\begin{column}{4cm}
			\begin{block}{SymTab Procedures}
			\SymTabProcedure
			\end{block}
		\end{column}
	
		\begin{column}{3cm}
			\begin{block}{Object \& Type}
			\Object	
			\Type
			\end{block}
		\end{column}
		
%		\begin{column}{3cm}
%			\begin{block}{Type}
%			\Type
%			\end{block}
%		\end{column}
%		
		\begin{column}{3cm}
			\begin{block}{Symbol Table}
			\SymTab
			\end{block}
		\end{column}
		
	\end{columns}
\end{frame}

\begin{frame}{Symbol Table}
	\begin{block}{Stack Structure}
			\includegraphics[scale=0.37]{SymTab.pdf}	
	\end{block}					
\end{frame}

\subsection{Virtual Machine}

\begin{frame}{Virtual Machine}
	\begin{columns}
		\begin{column}{5cm}
		\begin{block}{Overview}
				\begin{itemize}
					\item implemented in C
					\item instruction format: risc (as shown in class)
					\item initializes globalpointer \& stackpointer
					\item termination if stack is empty		
				\end{itemize}
			\end{block}
		\end{column}
		\begin{column}{5.5cm}			
			\begin{block}{Memory Structure VM}
\includegraphics[scale=0.3]{memory.pdf}
			\end{block}
		\end{column}
	\end{columns}
\end{frame}

\end{document}
